//package com.pt5.pthouduan.service.impl;
//
//import com.pt5.pthouduan.entity.TrackeredTorrentWithStats;
//import com.pt5.pthouduan.service.TorrentStatsService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import javax.sql.DataSource;
//import java.sql.Connection;
//import java.sql.PreparedStatement;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//import java.util.ArrayList;
//import java.util.List;
//
//@Service
//public class TorrentStatsServiceImpl implements TorrentStatsService {
//    @Autowired
//    private DataSource dataSource;
//
//    // 获取种子的完整做种者列表
//    public List<TrackeredTorrentWithStats.SeederInfo> getSeederDetails(String infoHash) {
//        System.out.println("执行了查找details");
//        String sql = """
//            SELECT u.username, s.*
//            FROM seeding_stats s
//            JOIN user u ON s.user_id = u.userid
//            WHERE s.info_hash = ? AND s.last_event != 'stopped'
//            ORDER BY s.uploaded DESC""";
//
//        try (Connection conn = dataSource.getConnection();
//             PreparedStatement stmt = conn.prepareStatement(sql)) {
//            stmt.setString(1, infoHash);
//            ResultSet rs = stmt.executeQuery();
//
//            List<TrackeredTorrentWithStats.SeederInfo> result = new ArrayList<>();
//            while (rs.next()) {
//                TrackeredTorrentWithStats.SeederInfo info = new TrackeredTorrentWithStats.SeederInfo();
//                info.setUsername(rs.getString("username"));
//                info.setUploaded(rs.getLong("uploaded"));
//                info.setDownloaded(rs.getLong("downloaded"));
//                info.setUploadSpeed(rs.getDouble("upload_speed"));
//                info.setDownloadSpeed(rs.getDouble("download_speed"));
//                info.setLastEvent(rs.getString("last_event"));
//                info.setLastActive(rs.getTimestamp("last_active"));
//                info.setClient(rs.getString("client"));
//                result.add(info);
//                System.out.println(info);
//            }
//            return result;
//        } catch (SQLException e) {
//            throw new RuntimeException("Database error", e);
//        }
//    }
//}
